﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.SlotJoint.FocusExtension
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Windows;
using Tecnomatix.Engineering.Ui.WPF;


namespace DnProcessSimulateCommands.SlotJoint;

public static class FocusExtension
{
  public static readonly DependencyProperty IsFocusedProperty = DependencyProperty.RegisterAttached("IsFocused", typeof (bool), typeof (FocusExtension), (PropertyMetadata) new UIPropertyMetadata((object) false, new PropertyChangedCallback(FocusExtension.OnIsFocusedPropertyChanged)));

  public static bool GetIsFocused(DependencyObject obj)
  {
    return (bool) obj.GetValue(FocusExtension.IsFocusedProperty);
  }

  public static void SetIsFocused(DependencyObject obj, bool value)
  {
    obj.SetValue(FocusExtension.IsFocusedProperty, (object) value);
  }

  private static void OnIsFocusedPropertyChanged(
    DependencyObject d,
    DependencyPropertyChangedEventArgs e)
  {
    UIElement uiElement = (UIElement) d;
    if ((bool) e.NewValue)
    {
      switch (d)
      {
        case Tx3DVectorControl _:
          ((Tx3DVectorControl) d).Focus();
          break;
        case TxObjEditBoxControl _:
          ((TxObjEditBoxControl) d).Focus();
          break;
        default:
          uiElement.Focus();
          break;
      }
    }
    else
    {
      switch (d)
      {
        case Tx3DVectorControl _:
          ((Tx3DVectorControl) d).LoseFocus();
          break;
        case TxObjEditBoxControl _:
          ((TxObjEditBoxControl) d).LoseFocus();
          break;
      }
    }
  }
}
